```vue
<template>
  <view class="container">
    <!-- 渐变背景层 -->
    <view class="bg-layer"></view>
    
    <!-- 头部区域 -->
    <view class="header" aria-label="页面头部">
      <view class="header-content">
        <uni-icons 
          type="arrow-left" 
          size="24" 
          color="#fff" 
          @click="navigateBack"
          class="back-icon"
          aria-label="返回上一页"
        ></uni-icons>
        <text class="title">班级学习统计</text>
      </view>
    </view>

    <!-- 班级选择器 -->
    <view class="filter-section" aria-label="班级选择区域">
      <view class="class-selector">
        <uni-icons type="list" size="18" color="#3a7bd5"></uni-icons>
        <picker
          :range="classOptions"
          range-key="text"
          :value="selectedClassIndex"
          @change="onClassChange"
          class="selector-select"
          aria-label="选择班级"
        >
          <text>{{ selectedClass || '请选择班级' }}</text>
        </picker>
      </view>
    </view>

    <!-- 统计列表 -->
    <scroll-view scroll-y class="stats-list" :scroll-top="scrollTop" aria-label="学生统计列表">
      <!-- 数据卡片 -->
      <view 
        v-for="(student, idx) in stats" 
        :key="student.student_id" 
        class="stats-card"
      >
        <view class="card-header">
          <view class="left-section">
            <view class="rank-container">
              <text class="rank" :class="{ 'rank-top': idx < 3 }">{{ idx + 1 }}</text>
            </view>
            <image 
              class="student-avatar" 
              :src="student.avatar || '/static/default-avatar.png'" 
              mode="aspectFill"
              aria-hidden="true"
            ></image>
            <text class="student-name">{{ student.name || '未知学生' }}</text>
          </view>
          <view class="right-section">
            <view class="badge" v-if="student.points >= 100" aria-label="优秀学生徽章">
              <uni-icons type="star-filled" size="14" color="#FFD700"></uni-icons>
            </view>
          </view>
        </view>
        
        <view class="stats-info">
          <view class="stat-item stat-points">
            <uni-icons type="star" size="18" color="#FF9800"></uni-icons>
            <text class="stat-value">{{ student.points || 0 }}</text>
            <text class="stat-label">积分</text>
          </view>
          
          <view class="stat-item stat-questions">
            <uni-icons type="list" size="18" color="#F44336"></uni-icons>
            <text class="stat-value">{{ student.total_questions || 0 }}</text>
            <text class="stat-label">总答题</text>
          </view>
          
          <view class="stat-item stat-rate">
            <uni-icons type="medal" size="18" color="#4CAF50"></uni-icons>
            <text class="stat-value">{{ student.correct_rate || '0.00' }}%</text>
            <text class="stat-label">正确率</text>
          </view>
        </view>
      </view>

      <!-- 空状态 -->
      <view v-if="!stats.length && !loading" class="empty-state" aria-label="无数据提示">
        <text class="empty-text">暂无学生数据</text>
        <text class="empty-tip">请检查班级数据或联系管理员</text>
      </view>
      
      <!-- 加载更多 -->
      <uni-load-more 
        v-if="loading" 
        status="loading" 
        color="#3a7bd5"
        aria-label="正在加载数据"
      ></uni-load-more>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      teacher: {},
      stats: [],
      loading: false,
      scrollTop: 0,
      classOptions: [],
      selectedClass: '',
      selectedClassIndex: 0
    };
  },
  onLoad() {
    this.loadTeacherData();
  },
  methods: {
    loadTeacherData() {
      const user = uni.getStorageSync('user') || {};
      if (!user.id) {
        uni.redirectTo({ url: '/pages/student/login' });
        return;
      }
      this.teacher = user;
      console.log('教师信息:', this.teacher);
      if (Array.isArray(this.teacher.className) && this.teacher.className.length > 0) {
        this.classOptions = this.teacher.className.map(className => ({
          value: className,
          text: className
        }));
        this.selectedClass = this.teacher.className[0];
        this.selectedClassIndex = 0;
        this.loadStats();
      } else {
        uni.showToast({ title: '无管理班级，请联系管理员', icon: 'none' });
      }
    },
    
    async loadStats() {
      if (!this.selectedClass) {
        this.stats = [];
        this.loading = false;
        return;
      }
      this.loading = true;
      this.stats = [];
      this.scrollTop = 0;
      
      try {
        const res = await uniCloud.callFunction({
          name: 'getClassStats',
          data: { 
            className: this.selectedClass,
            teacher_id: this.teacher.id 
          }
        });
        console.log('getClassStats 返回:', res);
        if (res.result.code === 0) {
          this.stats = res.result.data.map(item => ({
            ...item,
            correct_rate: item.total_questions 
              ? ((item.correct_count || 0) / item.total_questions * 100).toFixed(2)
              : '0.00',
            progress: item.total_lessons 
              ? Math.round((item.completed_lessons || 0) / item.total_lessons * 100)
              : 0
          }));
          uni.showToast({ title: '加载统计数据成功', icon: 'success' });
        } else {
          uni.showToast({ title: res.result.msg || '获取数据失败', icon: 'none' });
        }
      } catch (e) {
        console.error('加载统计失败:', e);
        uni.showToast({ title: '网络请求失败，请联系管理员', icon: 'none' });
      } finally {
        this.loading = false;
      }
    },
    
    onClassChange(e) {
      this.selectedClassIndex = e.detail.value;
      this.selectedClass = this.classOptions[this.selectedClassIndex].value;
      this.loadStats();
    },
    
    navigateBack() {
      uni.navigateBack();
    }
  }
};
</script>

<style scoped>
/* 全局容器 */
.container {
  position: relative;
  min-height: 100vh;
  background: #f8fafd;
  z-index: 1;
}

/* 渐变背景层 */
.bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 380rpx;
  background: linear-gradient(135deg, #3a7bd5 0%, #7cc4ff 100%);
  border-radius: 0 0 56rpx 56rpx;
  box-shadow: 0 16rpx 40rpx rgba(58, 123, 213, 0.25);
  z-index: 0;
}

/* 头部区域 */
.header {
  padding: 80rpx 32rpx 32rpx;
  position: relative;
  z-index: 2;
}

.header-content {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 32rpx;
  padding: 24rpx 32rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}

.back-icon {
  padding: 16rpx;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: transform 0.2s, background 0.2s;
}

.back-icon:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.5);
}

.title {
  font-size: 44rpx;
  font-weight: 700;
  color: #fff;
  margin-left: 20rpx;
}

/* 班级选择器 */
.filter-section {
  padding: 0 32rpx 40rpx;
  position: relative;
  z-index: 2;
}

.class-selector {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 64rpx;
  padding: 28rpx 40rpx;
  box-shadow: 0 8rpx 24rpx rgba(58, 123, 213, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}

.class-selector:active {
  transform: scale(0.98);
  box-shadow: 0 4rpx 12rpx rgba(58, 123, 213, 0.1);
}

.selector-select {
  flex: 1;
  font-size: 32rpx;
  font-weight: 500;
  color: #333;
  margin: 0 20rpx;
}

/* 统计列表 */
.stats-list {
  padding: 0 32rpx 40rpx;
  height: calc(100vh - 380rpx);
  width: 100%;
  box-sizing: border-box;
}

/* 数据卡片 */
.stats-card {
  position: relative;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(255, 255, 255, 0.98) 50%,
    rgba(255, 255, 255, 0.95) 100%
  );
  border-radius: 32rpx;
  padding: 40rpx;
  margin: 0 auto 32rpx;
  box-shadow: 0 16rpx 32rpx rgba(0, 0, 0, 0.08);
  border-left: 4rpx solid rgba(58, 123, 213, 0.3);
  border-right: 4rpx solid rgba(58, 123, 213, 0.3);
  width: 100%;
  max-width: calc(100% - 8rpx);
  box-sizing: border-box;
  /* 添加 transition 支持 CSS 动画 */
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

/* 使用 :active 伪类实现点击缩放效果 */
.stats-card:active {
  transform: scale(0.98);
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.12);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32rpx;
}

.left-section {
  display: flex;
  align-items: center;
}

.right-section {
  display: flex;
  align-items: center;
}

.rank-container {
  position: relative;
  width: 64rpx;
  height: 64rpx;
  margin-right: 28rpx;
  flex-shrink: 0;
}

.rank {
  position: absolute;
  top: 0;
  left: 0;
  width: 64rpx;
  height: 64rpx;
  background: #e8ecef;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32rpx;
  font-weight: 700;
  color: #666;
}

.rank-top {
  background: linear-gradient(135deg, #FFD700, #FFCA28);
  color: #fff;
}

.student-avatar {
  width: 100rpx;
  height: 100rpx;
  border-radius: 50%;
  border: 4rpx solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
  margin-right: 16rpx;
}

.student-name {
  font-size: 38rpx;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200rpx;
}

.badge {
  background: rgba(255, 215, 0, 0.2);
  padding: 12rpx 24rpx;
  border-radius: 32rpx;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* 统计信息 */
.stats-info {
  display: flex;
  justify-content: space-between;
  gap: 24rpx;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 24rpx;
  padding: 24rpx 0;
  transition: transform 0.2s, background 0.2s;
}

.stat-item:active {
  transform: scale(0.95);
}

.stat-points {
  background: linear-gradient(135deg, rgba(255, 152, 0, 0.1), rgba(255, 152, 0, 0.05));
}

.stat-points:active {
  background: linear-gradient(135deg, rgba(255, 152, 0, 0.2), rgba(255, 152, 0, 0.1));
}

.stat-questions {
  background: linear-gradient(135deg, rgba(244, 67, 54, 0.1), rgba(244, 67, 54, 0.05));
}

.stat-questions:active {
  background: linear-gradient(135deg, rgba(244, 67, 54, 0.2), rgba(244, 67, 54, 0.1));
}

.stat-rate {
  background: linear-gradient(135deg, rgba(76, 175, 80, 0.1), rgba(76, 175, 80, 0.05));
}

.stat-rate:active {
  background: linear-gradient(135deg, rgba(76, 175, 80, 0.2), rgba(76, 175, 80, 0.1));
}

.stat-value {
  font-size: 40rpx;
  font-weight: 700;
  color: #333;
  margin: 12rpx 0 8rpx;
  width: 100%;
  text-align: center;
}

.stat-label {
  font-size: 28rpx;
  color: #888;
  width: 100%;
  text-align: center;
}

/* 空状态 */
.empty-state {
  position: relative;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(255, 255, 255, 0.98) 50%,
    rgba(255, 255, 255, 0.95) 100%
  );
  border-radius: 32rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 160rpx 0;
  margin: 0 auto 32rpx;
  width: 100%;
  max-width: calc(100% - 8rpx);
  box-sizing: border-box;
}

.empty-text {
  font-size: 36rpx;
  font-weight: 500;
  color: #666;
  margin-bottom: 24rpx;
}

.empty-tip {
  font-size: 30rpx;
  color: #aaa;
}

/* 加载更多 */
uni-load-more {
  margin: 40rpx 0;
}
</style>